class_name PointEditor extends Node2D

var kong:Texture2D = preload("res://地图编辑/地图块-编辑模式/图片/空地.png")
var shan:Texture2D = preload("res://地图编辑/地图块-编辑模式/图片/山脉.png")
var shui:Texture2D = preload("res://地图编辑/地图块-编辑模式/图片/江水.png")
var lin:Texture2D = preload("res://地图编辑/地图块-编辑模式/图片/树林.png")
var sha:Texture2D = preload("res://地图编辑/地图块-编辑模式/图片/沙漠.png")
var jing:Texture2D = preload("res://地图编辑/地图块-编辑模式/图片/水晶.png")

var arr_terrain:Dictionary = {0:kong,1:shan,2:shui,3:lin,4:sha,5:jing}
var real_terrain:int = 0
var x:float = 0 
var y:float = 0 
var id:String = ""
var is_view = false

func _ready():
	visible = false
	$"Area2D/CollisionPolygon2D".disabled = true
	await get_tree().create_timer(4).timeout
	$"Area2D/CollisionPolygon2D".disabled = false

func init(xx:float,yy:float):
	changeTerrain(0)
	self.x = xx
	self.y = yy
	position = Vector2(x*87,-y*75)
	id = GameUtils.getPointId(x,y)
	ObjectManager.editor.map_points.merge({id:self})
	await get_tree().create_timer((abs(x)+abs(y))*0.1).timeout
	visible = true
	$"AnimationPlayer".play("降落")

# 地形显示变化，不代表真实地形
func changeTerrain(terrain:int):
	if terrain == -1 && real_terrain == -1:
		real_terrain = 0
	else:
		real_terrain = terrain
	if real_terrain == -1 :
		modulate = Color(1, 1, 1, 0)
	else:
		modulate = Color(1, 1, 1, 1)
		$"六边形外圈/六边形内圈/Sprite2D".texture = arr_terrain[real_terrain]

func _on_mouse_entered():
	$"AnimationPlayer".play("鼠标指向")
	var editor = ObjectManager.editor as Editor
	editor.selected_point = self

func _on_mouse_exited():
	$"AnimationPlayer".play("鼠标移开")
	
